<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<script type="text/javascript">
	var $tg ;
	$(function() {
		$tg = $("#tg").treegrid({
			 url: base.contextPath+"/sysmgr/menu/treegrid.do",
			 idField: 'id', treeField: 'name',singleSelect:false, border: false,
	         remoteSort: false, fit: true, striped:true, cascadeCheck: true,
	         frozenColumns: [[
  	         	{ field: 'ck', checkbox: true },
    	        { field: 'id', title: 'ID', width: 50, hidden: true }
   	         ]],
	         columns: [[
             	{ field: 'name', title: '名称', width: 200, sortable: true },
			    { field: 'type', title: '菜单类型', width: 70, sortable: true, formatter:function(value,row){
			    	if(value == "R"){return "导航栏目";}else if(value == "F"){return "<font color='green'>导航菜单</font>";}else{return "<font color='orange'>菜单操作</font>";}
			    }},
			    { field: 'href', title: '链接地址', width: 350 },
			    { field: 'isShow', title: '是否显示', width: 60, sortable: true, align: 'center', formatter:function(value,row){
			    	return (value==0?"<font color='green'>显示</font>":"<font color='red'>不显示</font>") ;
			    }}
	         ]],
	         onLoadSuccess: function(row, data) {
	        	 $.fn.treegrid.extensions.onLoadSuccess.apply(this, arguments);
	        	 var menu_ids = "${permit.menu_ids}" ;
	        	 if(menu_ids.length > 0) {
		        	 $.each(menu_ids.split(","), function(i, p) {
			        	 $tg.treegrid("select", p) ;
		        	 });
	        	 }
	         }
		}) ;
		
	});
	
	//验证表单
	var submitForm = function($d, $dg, flag) { 
		
		var ids = [];
		var rows = $tg.treegrid('getChecked');
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				ids.push(rows[i].id);
			}
		}
		
		var role_id = "${permit.id}" ;
		$.easyui.loading({ msg: "数据添加中，请稍等..."});
		$.post(base.contextPath+"/sysmgr/permits/doNotNeedAuth_addMenus_role.do", {id: role_id, menu_ids: ids.join(',')}, function(result) {
			if (result.status) {
				alertify.success(result.msg);$.easyui.loaded();
				if(flag==undefined||flag==false){$d.dialog("close") ;}
			} else {
				$.easyui.loaded();warning.success(result.msg);
			}
		}, 'json').error(function() { $.easyui.loaded(); });
	};
	
	
</script>
<div id="tg"></div>
